From 0e0f39af2e6585d7b61cf67652cdc0c2b2f06eb8 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 18 Jan 2023 19:44:27 -0800 Subject: pots --- src/routes/(app)/invoice/[hash]/+layout.server.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/routes/(app)/invoice/[hash]/+layout.server.js (limited to 'src/routes/(app)/invoice/[hash]/+layout.server.js') diff --git a/src/routes/(app)/invoice/[hash]/+layout.server.js b/src/routes/(app)/invoice/[hash]/+layout.server.js new file mode 100644 index 00000000..61a479ab --- /dev/null +++ b/src/routes/(app)/invoice/[hash]/+layout.server.js @@ -0,0 +1,19 @@ +import Qr from 'qrcode-base64'; +import { get } from '$lib/utils'; +import { redirect } from '@sveltejs/kit'; + +export async function load({ depends, params, url }) { + depends('app:invoice'); + + let { hash } = params; + let invoice = await get(`/invoice?hash=${hash}`); + let { amount, received } = invoice; + amount = parseInt(amount); + + let paid = (!amount && received) || (amount > 0 && received >= amount); + if (paid && !url.pathname.endsWith('paid')) throw redirect(307, `/invoice/${hash}/paid`); + + let sm = Qr.drawImg(invoice.text, { size: 300 }); + + return { hash, invoice, sm, lg: sm }; +} -- cgit v1.2.3